#
# @lc app=leetcode.cn id=1512 lang=python3
#
# [1512] 好数对的数目
#

# @lc code=start
from collections import defaultdict
from typing import Counter, List


class Solution:
    def numIdenticalPairs(self, nums: List[int]) -> int:
        cnt = defaultdict(int)
        ans = 0
        for i,x in enumerate(nums):
            ans += cnt[x]
            cnt[x] += 1
        
        return ans

# @lc code=end

